const variables = this.pageObj.getVariables();

const sysEnvType = variables.find(v => v.name === 'sysEnvType')?.value || '';
const userId = variables.find(v => v.name === 'userId')?.value || '';
const environmentType = variables.find(v => v.name === 'environmentType')?.value || '';
const apiUrl = sysEnvType == "gt" ? `/${environmentType}Basics/basics-main/system/workType/list` : "http://192.168.1.221:8089/admin/role/getRoleListByUserId";

const AuthToken = variables.find(item => item.name === 'AuthToken').value;


const table = this.pageObj.getApiWidgetByAliasName('选择系统表格')?.widgetObj

const option = {
    method: 'GET',
    headers: {
        'Content-Type': 'application/json',
        "Authorization": AuthToken
    }
}

fetch(`${apiUrl}?userId=${ userId }`, option).then(res => res.json()).then(async res => {
    if (sysEnvType == "gt") { // 国铁
        let { result, success } = res;
        if (success) {
            let _data = result.rows || [];
            table.setData([{
                data: _data
            }]);

            table.render();
        }
    } else { // 国网
        let { code, data } = res;
        data = data.map(item => {
            return {
                ...item,
                careerName: item.roleName,
                careerCode: item.roleCode,
            }
        });

        if (code === 200) {
            table.setData([{
                data
            }]);

            table.render();
        }
    }
})
